package cn.btks.databasehandler.handle.repository;

import cn.btks.databasehandler.handle.pojo.BackUpConfig;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author lijun
 * @Date 2020/12/28 12:07
 */
@Repository
public interface BackUpConfigRepository extends JpaRepository<BackUpConfig,Long>, JpaSpecificationExecutor<BackUpConfig> {

    /**
     * 根据是否启动查询备份配置信息
     * @param isStarted
     * @return
     */
    List<BackUpConfig> findAllByIsStarted(Integer isStarted);

    /**
     * 根据配置名称查询配置信息
     * @param configName
     * @return
     */
    BackUpConfig findByConfigName(String configName);

    /**
     * 更新备份配置是否启动
     * @param id
     * @param isStarted
     * @return
     */
    @Modifying
    @Query(value = "update back_up_config set is_started = ?2 where id = ?1", nativeQuery = true)
    int updateIsStarted(Long id,Integer isStarted);

    /**
     * 根据ID删除配置信息
     *
     * @param tableId
     * @return
     */
    @Modifying
    @Query(value = "delete from back_up_config where id = ?1", nativeQuery = true)
    int deleteByConfigId(Long tableId);
}
